#pragma once

#include <string>
#include <Windows.h>

std::string wcs2mbs(const std::wstring& strSrc)
{
	auto nNeed = ::WideCharToMultiByte(CP_ACP, 0, strSrc.c_str(), strSrc.size(), nullptr, 0, nullptr, nullptr);
	char* ch = new char[nNeed + 1];
	memset(ch, 0, nNeed + 1);
	nNeed = ::WideCharToMultiByte(CP_ACP, 0, strSrc.c_str(), strSrc.size(), ch, nNeed, nullptr, nullptr);
	std::string str(ch);
	delete[]ch;
	return str;
}

std::string wcs2mbs(const wchar_t* lpszSrc)
{
	if (!lpszSrc)
		return "";
	return wcs2mbs(std::wstring(lpszSrc));
}

std::wstring mbs2wcs(const std::string& strSrc)
{
	auto nNeed = ::MultiByteToWideChar(CP_ACP, 0, strSrc.c_str(), strSrc.size(), nullptr, 0);
	wchar_t* ch = new wchar_t[nNeed + 1];
	memset(ch, 0, (nNeed + 1)*sizeof(wchar_t));
	nNeed = ::MultiByteToWideChar(CP_ACP, 0, strSrc.c_str(), strSrc.size(), ch, nNeed);
	std::wstring str(ch);
	delete[]ch;
	return str;
}

std::wstring mbs2wcs(const char* lpszSrc)
{
	if (!lpszSrc)
		return L"";
	return mbs2wcs(std::string(lpszSrc));
}
